<!--
 * @Description: 选择关联客户
 * @Autor: 刘诗文
 * @Date: 2020-12-08 16:51:30
 * @LastEditors: 何兴家
 * @LastEditTime: 2021-02-26 14:36:31
-->
<template>
  <div>
    <TopFilter :list="topFilterList" :cols="3" :labelWidth="105" @filterChange="changeHandle" @onCollapse="collapseHandle"></TopFilter>
    <FilterTable
      ref="table"
      height="500"
      selectionType="single"
      :columns="columns"
      :fetchapi="fetchapi"
      :params="fetchParams"
      :datakey="'rows'"
      columnsRef="chooseAssociatedCustomerslsw"
      :onColumnsChange="columns => (this.columns = columns)"
      :onRowSelectChange="onRowSelectChange"
    >
    </FilterTable>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
      <el-button @click="cancelHandle">取消</el-button>
      <el-button type="primary" @click="saveHandler">保存</el-button>
    </div>
  </div>
</template>
<script>
import { dictionary } from '@/utils/dictMixin';
import { getOwnerInfo } from '@/api/customerRepair/vehicleOwnerManagement/vehicleChange';
export default {
  name: 'chooseAssociatedCustomers',
  mixins: [dictionary],
  props: {
    type: {
      type: String,
      default: 'add'
    },
    resData: {
      type: Object,
      default: {}
    }
  },
  data() {
    this.selectedData = null;
    this.BaseTable = null;
    return {
      topFilterList: this.createTopFilterList(),
      columns: this.createTableColumns(),
      fetchapi: getOwnerInfo,
      fetchParams: { pageNum: 1, linkType: 'true', ownerNoFlag: this.resData.ownerNo }
    };
  },
  mounted() {
    this.BaseTable = this.$refs.table;
  },
  methods: {
    createTopFilterList() {
      return [
        {
          type: 'INPUT',
          label: '客户编号',
          fieldName: 'ownerNo'
        },
        {
          type: 'INPUT',
          label: '客户姓名',
          fieldName: 'ownerName'
        },
        {
          type: 'INPUT',
          label: '客户手机',
          fieldName: 'mobile'
        },
        {
          type: 'INPUT',
          label: '客户电话',
          fieldName: 'phone'
        }
      ];
    },
    createTableColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '客户编号',
          dataIndex: 'ownerNo',
          width: 120,
          showOverflowTooltip: true
        },
        {
          title: '客户姓名',
          dataIndex: 'ownerName',
          width: 90,
          showOverflowTooltip: true
        },
        {
          title: '客户电话',
          dataIndex: 'phone',
          showOverflowTooltip: true
        },
        {
          title: '客户手机号',
          dataIndex: 'mobile',
          showOverflowTooltip: true
        },
        {
          title: '车牌号',
          dataIndex: 'license',
          showOverflowTooltip: true
        },
        {
          title: 'VIN',
          dataIndex: 'vin',
          showOverflowTooltip: true
        }
      ];
    },
    changeHandle(val) {
      this.fetchParams = Object.assign({}, val);
    },
    collapseHandle() {
      this.$nextTick(this.BaseTable.EXECUTE_RESET_HEIGHT);
    },
    onRowSelectChange(row) {
      if (!row.length) {
        this.selectedData = null;
      } else {
        this.selectedData = row[0];
      }
    },
    // 确认
    saveHandler() {
      this.$emit('chooseAssociatedData', this.selectedData);
    },
    // 取消
    cancelHandle() {
      this.$emit('close', false);
    }
  }
};
</script>
<style lang="less" scoped></style>
